﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.WebComponent
Imports AugmentLib.InputOutput.Encryption

Partial Class RenReportEntry
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session.Item("StaffId") Is Nothing Then
            Response.Redirect("default.aspx")
        End If

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            lblStaffUID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString

            If Not Request.QueryString("id") Is Nothing Then
                CBEDelete.ConfirmText = "Are you sure you want to delete this report entry?"
                GetddlName()
                lblRenReportUID.Text = SymmetricDecryptFromHex(Request.QueryString("id"), "augment")
                LoadRenReport()
                lblDocType.Text = "EDIT"
                btnNew.Enabled = False
                ddlName.Enabled = False
                btnDelete.Visible = True

                If lblStaffType.Text = "1" Then
                    ddlInput.Enabled = False
                    ddlName.Enabled = False
                    txtName.Enabled = False
                    txtMobile.Enabled = False
                    txtPhone.Enabled = False
                    txtFax.Enabled = False
                    txtCompany.Enabled = False
                    txtEmail.Enabled = False
                    txtAddress.Enabled = False
                    ddlStatus.Enabled = False
                    ddlCountry.Enabled = False
                    ddlState.Enabled = False
                    ddlLocation.Enabled = False
                    ddlRoad.Enabled = False
                    ddlProject.Enabled = False
                    ddlPropertyType.Enabled = False
                    ddlListType.Enabled = False
                    txtPriceFrom.Enabled = False
                    txtPriceTo.Enabled = False
                    txtTitle.Enabled = False
                    txtRemarks.Enabled = False
                    txtBossRemarks.Enabled = True
                ElseIf lblStaffType.Text = "3" Then
                    If lblCreateBy.Text = lblStaffUID.Text Then
                        ddlName.Enabled = False
                        txtBossRemarks.Enabled = False
                    Else
                        ddlInput.Enabled = False
                        ddlName.Enabled = False
                        txtName.Enabled = False
                        txtMobile.Enabled = False
                        txtPhone.Enabled = False
                        txtFax.Enabled = False
                        txtCompany.Enabled = False
                        txtEmail.Enabled = False
                        txtAddress.Enabled = False
                        ddlStatus.Enabled = False
                        ddlCountry.Enabled = False
                        ddlState.Enabled = False
                        ddlLocation.Enabled = False
                        ddlRoad.Enabled = False
                        ddlProject.Enabled = False
                        ddlPropertyType.Enabled = False
                        ddlListType.Enabled = False
                        txtPriceFrom.Enabled = False
                        txtPriceTo.Enabled = False
                        txtTitle.Enabled = False
                        txtRemarks.Enabled = False
                        txtBossRemarks.Enabled = False
                    End If
                Else
                    ddlName.Enabled = False
                    txtBossRemarks.Enabled = False
                End If
            Else
                'display date
                Dim dt As DateTime = DateTime.ParseExact(SymmetricDecryptFromHex(Request.QueryString("date"), "augment"), "d/M/yyyy", Nothing)
                lblDate.Text = Format(dt, "dd-MMM-yyyy")
                If lblDate.Text = "" Then
                    lblDate.Text = Format(Today.Date, "dd-MMM-yyyy")
                End If
                divContentGeneral.Visible = True
                divContentProperty.Visible = True
                divContentDetails.Visible = True
                trBoss.Visible = True
                'if boss enable comment textbox
                'else disable comment textbox :P
                If lblStaffType.Text = "1" Then
                    txtBossRemarks.Enabled = True
                    'disable other things except the boss comment
                Else
                    txtBossRemarks.Enabled = False
                End If
                lblDocType.Text = "NEW"
                btnNew.Enabled = True
                'Load dropdownlist
                GetddlName()
                GetddlCountry(ddlCountry)
                GetddlState(ddlState, ddlCountry)
                GetddlLocation(ddlLocation, ddlState)
                GetddlRoad(ddlRoad, ddlLocation)
                GetddlProject(ddlProject, ddlRoad)
                GetddlPropertyType(ddlPropertyType)
                BtnSave.ValidationGroup = "RenReport"
                btnDelete.Visible = False
            End If

           
        End If
    End Sub

    Protected Sub LoadRenReport()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.AddParameter("RenReportId", Data.SqlDbType.UniqueIdentifier, New Guid(lblRenReportUID.Text))
        objDB.dbVariable.SQLString = "SELECT RR.RenContactId, RR.RenReportType, RR.Title, RR.Remarks, RR.BossRemarks, RC.Name, " & _
                                    "RR.RenDate, RR.RenMonth, RR.RenYear, RR.CreateDate, RC.Phone, RC.Mobile, RC.Fax, " & _
                                    "RC.Company, RC.Email, RC.Address, RC.Status, RR.CreateBy FROM AW_RenReport RR LEFT JOIN AW_RenContact RC " & _
                                    "ON RR.RenContactId = RC.RenContactId WHERE RR.RenReportId=@RenReportId AND RR.StatusDelete=0"
        objDB.FillData(TempDT, "RenReport", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each Readrow As Data.DataRow In TempDT.Rows
            ddlInput.SelectedValue = Readrow.Item("RenReportType").ToString
            ddlInput.Enabled = False
            lblDate.Text = Format(Date.ParseExact(Readrow.Item("RenDate").ToString & "-" & Readrow.Item("RenMonth").ToString & "-" & Readrow.Item("RenYear").ToString, "d-M-yyyy", Nothing), "dd-MMM-yyyy")
            'lblDate.Text = Format(Readrow.Item("CreateDate"), "dd-MMM-yyyy")
            ddlName.SelectedValue = Readrow.Item("RenContactId").ToString
            txtPhone.Text = Readrow.Item("Phone").ToString
            txtMobile.Text = Readrow.Item("Mobile").ToString
            txtFax.Text = Readrow.Item("Fax").ToString
            txtCompany.Text = Readrow.Item("Company").ToString
            txtEmail.Text = Readrow.Item("Email").ToString
            txtAddress.Text = Readrow.Item("Address").ToString
            ddlStatus.SelectedValue = Readrow.Item("Status").ToString
            txtTitle.Text = Readrow.Item("Title").ToString
            txtRemarks.Text = Readrow.Item("Remarks").ToString
            txtBossRemarks.Text = Readrow.Item("BossRemarks").ToString
            lblCreateBy.Text = Readrow.Item("CreateBy").ToString
            If Readrow.Item("RenReportType").ToString = "1" Then
                'Report Entry
                divContentDetails.Visible = True
                divContentGeneral.Visible = True
                divContentProperty.Visible = True
                trBoss.Visible = True
                'if boss enable comment textbox
                'else disable comment textbox :P
                If lblStaffType.Text = "1" Then
                    txtBossRemarks.Enabled = True
                Else
                    txtBossRemarks.Enabled = False
                End If
                BtnSave.ValidationGroup = "RenReport"
            Else
                'Reminder
                divContentGeneral.Visible = False
                divContentProperty.Visible = False
                divContentDetails.Visible = True
                'hide boss comment field :D
                trBoss.Visible = False
                BtnSave.ValidationGroup = "Reminder"
            End If
        Next

        TempDT.Clear()
        TempDT.Reset()
        'if RenReport only do this
        If ddlInput.SelectedValue = "1" Then
            DeclareColumn(TempDT)
            objDB.dbVariable.SQLString = "SELECT RP.RenPropertyId, C.Country, RP.CountryId, S.State, RP.StateId, " & _
                                        "L.Location, RP.LocationId, R.Road, RP.RoadId, P.Project, RP.ProjectId, " & _
                                        "PP.Type AS PropertyType, RP.PropertyTypeId, " & _
                                        "CASE RP.ListType WHEN '0' THEN 'SR - Sales Residential' " & _
                                        "WHEN '1' THEN 'SC - Sales Commercial' WHEN '2' THEN 'SI - Sales Industrial' " & _
                                        "WHEN '3' THEN 'SL - Sales Land' WHEN '4' THEN 'RR - Rent Residential' " & _
                                        "WHEN '5' THEN 'RC - Rent Commercial' WHEN '6' THEN 'RI - Rent Industrial' " & _
                                        "WHEN '7' THEN 'RL - Rent Land' ELSE '' END as ListType, RP.ListType as ListTypeId, " & _
                                        "RP.PriceFrom, RP.PriceTo, 'O' AS Status, '1' AS Visible FROM AW_RenProperty RP " & _
                                        "LEFT JOIN AW_Country C ON RP.CountryId = C.CountryId LEFT JOIN AW_State S ON " & _
                                        "RP.StateId = S.StateId LEFT JOIN AW_Location L ON RP.LocationId = L.LocationId " & _
                                        "LEFT JOIN AW_Road R ON RP.RoadId = R.RoadId LEFT JOIN AW_Project P ON " & _
                                        "RP.ProjectId = P.ProjectId LEFT JOIN AW_PropertyType PP ON RP.PropertyTypeID = PP.TypeId " & _
                                        "WHERE RenContactId=@RenContactId"
            objDB.AddParameter("RenContactId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlName.SelectedValue))
            objDB.FillData(TempDT, "AW_RenProperty", Database.SQLCommandType.NormalString)
            objDB.CloseConnection()
            repProperty.DataSource = TempDT
            repProperty.DataBind()
            ViewState("DataTable") = TempDT
            VisibilityRepProperty()
        End If

        GetddlCountry(ddlCountry)
        GetddlState(ddlState, ddlCountry)
        GetddlLocation(ddlLocation, ddlState)
        GetddlRoad(ddlRoad, ddlLocation)
        GetddlProject(ddlProject, ddlRoad)
        GetddlPropertyType(ddlPropertyType)
    End Sub

    Protected Sub ddlInput_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlInput.SelectedIndexChanged
        If ddlInput.SelectedValue = "1" Then
            divContentGeneral.Visible = True
            divContentProperty.Visible = True
            divContentDetails.Visible = True
            trBoss.Visible = True
            'if boss enable comment textbox
            'else disable comment textbox :P
            If lblStaffType.Text = "1" Then
                txtBossRemarks.Enabled = True
            Else
                txtBossRemarks.Enabled = False
            End If
            BtnSave.ValidationGroup = "RenReport"
        ElseIf ddlInput.SelectedValue = "2" Then
            divContentGeneral.Visible = False
            divContentProperty.Visible = False
            divContentDetails.Visible = True
            'hide boss comment field :D
            trBoss.Visible = False
            BtnSave.ValidationGroup = "Reminder"
        End If
    End Sub

    Private Sub GetddlName()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If lblStaffType.Text = "2" Then
            objDB.dbVariable.SQLString = "SELECT Name, RenContactId FROM AW_RenContact WHERE StatusDelete=0 AND CreateBy=@CreateBy ORDER BY Name"
            objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        Else
            objDB.dbVariable.SQLString = "SELECT Name, RenContactId FROM AW_RenContact WHERE StatusDelete=0 ORDER BY Name"
        End If
        objDB.FillData(TempDT, "Country", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        If TempDT.Rows.Count = 0 Then
            trNew.Visible = True
            trUpdate.Visible = False
        Else
            With ddlName
                .DataSource = TempDT
                .DataTextField = "Name"
                .DataValueField = "RenContactId"
                .DataBind()
                .Items.Insert(0, "-SELECT-")
                .Items(0).Value = ""
            End With
            trUpdate.Visible = True
            trNew.Visible = False
        End If

    End Sub

    Private Sub GetddlCountry(ByVal ddlcountry As DropDownList)
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT CountryId,Country FROM AW_Country WHERE StatusDelete = 0 ORDER BY Country"
        objDB.FillData(TempDT, "Country", Database.SQLCommandType.NormalString)

        With ddlcountry
            .DataSource = TempDT
            .DataTextField = "Country"
            .DataValueField = "CountryId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlState(ByVal ddlState As DropDownList, ByVal ddlCountry As DropDownList)
        Dim strCountry As String
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If ddlCountry.SelectedValue = "" Then
            strCountry = Guid.Empty.ToString
        Else
            strCountry = ddlCountry.SelectedValue
        End If

        objDB.dbVariable.SQLString = "SELECT StateId,State FROM AW_State WHERE CountryId = @CountryId AND StatusDelete = 0 ORDER BY State"
        objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, New Guid(strCountry))
        objDB.FillData(TempDT, "State", Database.SQLCommandType.NormalString)

        With ddlState
            .DataSource = TempDT
            .DataTextField = "State"
            .DataValueField = "StateId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlLocation(ByVal ddlLocation As DropDownList, ByVal ddlState As DropDownList)
        Dim strState As String
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If ddlState.SelectedValue = "" Then
            strState = Guid.Empty.ToString
        Else
            strState = ddlState.SelectedValue
        End If

        objDB.dbVariable.SQLString = "SELECT LocationId,Location FROM AW_Location WHERE StateId = @StateId AND StatusDelete = 0 ORDER BY Location"
        objDB.AddParameter("StateId", Data.SqlDbType.UniqueIdentifier, New Guid(strState))
        objDB.FillData(TempDT, "Location", Database.SQLCommandType.NormalString)

        With ddlLocation
            .DataSource = TempDT
            .DataTextField = "Location"
            .DataValueField = "LocationId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlRoad(ByVal ddlRoad As DropDownList, ByVal ddlLocation As DropDownList)
        Dim strLocation As String
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If ddlLocation.SelectedValue = "" Then
            strLocation = Guid.Empty.ToString
        Else
            strLocation = ddlLocation.SelectedValue
        End If

        objDB.dbVariable.SQLString = "SELECT Road,RoadId FROM AW_Road WHERE StatusDelete = 0 AND LocationId = @LocationId ORDER BY Road"
        objDB.AddParameter("LocationId", Data.SqlDbType.UniqueIdentifier, New Guid(strLocation))
        objDB.FillData(TempDT, "AW_Road", Database.SQLCommandType.NormalString)

        With ddlRoad
            .DataSource = TempDT
            .DataTextField = "Road"
            .DataValueField = "RoadId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlProject(ByVal ddlProject As DropDownList, ByVal ddlRoad As DropDownList)
        Dim strRoad As String
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        If ddlRoad.SelectedValue = "" Then
            strRoad = Guid.Empty.ToString
        Else
            strRoad = ddlRoad.SelectedValue
        End If

        objDB.dbVariable.SQLString = "SELECT Project,ProjectId FROM AW_Project WHERE StatusDelete = 0 AND RoadId = @RoadId ORDER BY Project"
        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(strRoad))
        objDB.FillData(TempDT, "AW_Project", Database.SQLCommandType.NormalString)

        With ddlProject
            .DataSource = TempDT
            .DataTextField = "Project"
            .DataValueField = "ProjectId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Private Sub GetddlPropertyType(ByVal ddlPropertyType As DropDownList)
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType WHERE StatusDelete = 0 ORDER BY Type"
        objDB.FillData(TempDT, "AW_PropertyType", Database.SQLCommandType.NormalString)

        With ddlPropertyType
            .DataSource = TempDT
            .DataTextField = "Type"
            .DataValueField = "TypeId"
            .DataBind()
            .Items.Insert(0, "-SELECT-")
            .Items(0).Value = ""
        End With

        objDB.CloseConnection()

    End Sub

    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        GetddlState(ddlState, ddlCountry)
    End Sub

    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        GetddlLocation(ddlLocation, ddlState)
    End Sub

    Protected Sub ddlLocation_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlLocation.SelectedIndexChanged
        GetddlRoad(ddlRoad, ddlLocation)
    End Sub

    Protected Sub ddlRoad_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRoad.SelectedIndexChanged
        GetddlProject(ddlProject, ddlRoad)
    End Sub

    Protected Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click
        trNew.Visible = True
        trUpdate.Visible = False
        txtName.Text = String.Empty
        txtPhone.Text = String.Empty
        txtMobile.Text = String.Empty
        txtFax.Text = String.Empty
        txtEmail.Text = String.Empty
        txtCompany.Text = String.Empty
        txtAddress.Text = String.Empty
    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        'if same contactid for the same date, prompt error already exist, please proceed to edit the 
        'original entry (or just display original details) for user to edit
        Dim dd, mm, yy As String
        If lblDate.Text.Length = 0 Then
            lblMsgError.Text = "Error, Date is empty. Please select a date."
            divError.Visible = True
            Return
        End If
        Dim dt As DateTime = DateTime.ParseExact(lblDate.Text, "dd-MMM-yyyy", Nothing)
        dd = Format(dt, "dd")
        mm = Format(dt, "MM")
        yy = Format(dt, "yyyy")
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            If IsExistRecord(objDB, CInt(dd), CInt(mm), CInt(yy)) Then
                'Update
                'lblMsgError.Text = "Record exist in database."
                If (lblRenReportUID.Text.Length > 0) Then
                    'update ren contact, ren property and save remark
                    Dim strContactId As String
                    strContactId = ddlName.SelectedValue
                    dbContact("UPDATE", objDB, strContactId)
                    dbProperty(objDB, strContactId)
                    dbRenReport("UPDATE", objDB, strContactId, CInt(dd), CInt(mm), CInt(yy))
                End If

                'divError.Visible = True
            Else
                'save into database
                Dim strContactId As String
                If lblDocType.Text = "NEW" Then
                    lblRenReportUID.Text = Guid.NewGuid.ToString
                    If trUpdate.Visible Then
                        'update ren contact, ren property and save remark
                        strContactId = ddlName.SelectedValue
                        dbContact("UPDATE", objDB, strContactId)
                        dbProperty(objDB, strContactId)
                        dbRenReport("NEW", objDB, strContactId, CInt(dd), CInt(mm), CInt(yy))
                    Else
                        'save all
                        strContactId = Guid.NewGuid.ToString
                        dbContact("NEW", objDB, strContactId)
                        dbProperty(objDB, strContactId)
                        dbRenReport("NEW", objDB, strContactId, CInt(dd), CInt(mm), CInt(yy))
                    End If
                Else
                    'update ren contact, ren property and save remark
                    strContactId = ddlName.SelectedValue
                    dbContact("UPDATE", objDB, strContactId)
                    dbProperty(objDB, strContactId)
                    dbRenReport("UPDATE", objDB, strContactId, CInt(dd), CInt(mm), CInt(yy))
                End If
            End If
            objDB.DbTransCommit()
            objDB.CloseConnection()
            Response.Redirect("RenReport.aspx")
        Catch ex As Exception
            'error
            lblMsgError.Text = ex.Message
            divError.Visible = True
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
        End Try
    End Sub

    Private Sub dbContact(ByVal strType As String, ByVal objDB As Database, ByVal strContactId As String)
        If ddlInput.SelectedValue = "1" Then
            If strType = "UPDATE" Then
                objDB.dbVariable.SQLString = "UPDATE AW_RenContact SET Name=@Name, Phone=@Phone, Mobile=@Mobile, Fax=@Fax, " & _
                                            "Company=@Company, Email=@Email, Address=@Address, Status=@Status, RenId=@RenId WHERE RenContactId=@RenContactId"
            Else
                If IsExistName(objDB) Then
                    divError.Visible = True
                    lblMsgError.Text = "Name of the contact already exist. Please create a unique name"
                Else
                    objDB.dbVariable.SQLString = "INSERT INTO AW_RenContact(RenContactId, Name, Phone, Mobile, Fax, " & _
                                           "Company, Email, Address, Status, CreateDate, CreateBy, StatusDelete, RenId) " & _
                                           "Values(@RenContactId, @Name, @Phone, @Mobile, @Fax, @Company, @Email, " & _
                                           "@Address, @Status, @CreateDate, @CreateBy, @StatusDelete, @RenId)"
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                    objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
                    objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                End If
            End If
            objDB.AddParameter("RenId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
            objDB.AddParameter("RenContactId", Data.SqlDbType.UniqueIdentifier, New Guid(strContactId))
            objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtName.Text.Trim.ToUpper)
            If txtPhone.Text = String.Empty Then
                objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtPhone.Text.Trim)
            End If
            objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtMobile.Text.Trim)
            If txtFax.Text = String.Empty Then
                objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtFax.Text.Trim)
            End If
            If txtCompany.Text = String.Empty Then
                objDB.AddParameter("Company", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Company", Data.SqlDbType.NVarChar, txtCompany.Text.ToUpper.Trim)
            End If
            If txtEmail.Text = String.Empty Then
                objDB.AddParameter("Email", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtEmail.Text.Trim)
            End If
            If txtAddress.Text = String.Empty Then
                objDB.AddParameter("Address", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtAddress.Text.ToUpper.Trim)
            End If
            If ddlStatus.SelectedValue = String.Empty Then
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, DBNull.Value)
            Else
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, ddlStatus.SelectedValue)
            End If
            objDB.ExecuteQuery()
            objDB.ClearParameter()
        End If
    End Sub

    Private Sub dbRenReport(ByVal strType As String, ByVal objDB As Database, ByVal strContactId As String, ByVal dd As Integer, ByVal mm As Integer, ByVal yy As Integer)
        objDB.AddParameter("RenReportId", Data.SqlDbType.UniqueIdentifier, New Guid(lblRenReportUID.Text.Trim))

        If (strType <> "UPDATE") Then
            objDB.AddParameter("RenContactId", Data.SqlDbType.UniqueIdentifier, New Guid(strContactId))
        End If

        objDB.AddParameter("RenDate", Data.SqlDbType.TinyInt, dd)
        objDB.AddParameter("RenMonth", Data.SqlDbType.TinyInt, mm)
        objDB.AddParameter("RenYear", Data.SqlDbType.Int, yy)
        objDB.AddParameter("RenReportType", Data.SqlDbType.TinyInt, CInt(ddlInput.SelectedValue))
        objDB.AddParameter("Title", Data.SqlDbType.NVarChar, txtTitle.Text.ToUpper.Trim)
        objDB.AddParameter("Remarks", Data.SqlDbType.NVarChar, txtRemarks.Text.ToUpper.Trim)
        If txtBossRemarks.Text = String.Empty Then
            objDB.AddParameter("BossRemarks", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("BossRemarks", Data.SqlDbType.NVarChar, txtBossRemarks.Text.ToUpper.Trim)
        End If
        objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
        objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
        objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
        objDB.AddParameter("RenId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))

        If strType = "UPDATE" Then
            objDB.dbVariable.SQLString = "UPDATE AW_RenReport SET Title=@Title, Remarks=@Remarks, BossRemarks=@BossRemarks, " & _
                                        "RenDate=@RenDate,RenMonth=@RenMonth,RenYear=@RenYear," & _
                                        "UpdateBy=@UpdateBy, UpdateDate=@UpdateDate, RenId=@RenId Where RenReportId=@RenReportId"
            objDB.AddParameter("UpdateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
        Else
            objDB.dbVariable.SQLString = "INSERT INTO AW_RenReport (RenReportId, RenContactId, RenDate, RenMonth, RenYear, RenReportType, " & _
                                        "Title, Remarks, BossRemarks, CreateDate, CreateBy, StatusDelete, UpdateDate, UpdateBy, RenId) " & _
                                        "VALUES (@RenReportId, @RenContactId, @RenDate, @RenMonth, @RenYear, @RenReportType, " & _
                                        "@Title, @Remarks, @BossRemarks, @CreateDate, @CreateBy, @StatusDelete, @UpdateDate, @UpdateBy, @RenId)"
            objDB.AddParameter("UpdateBy", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
        End If
        objDB.ExecuteQuery(False)
        If ddlInput.SelectedValue = "2" Then
            If strType <> "UPDATE" Then
                objDB.dbVariable.SQLString = "INSERT INTO AW_Reminder (ReminderId, PropertyId, RenId, AffectedId, ReminderTYpe, StatusDelete, " & _
                         "CreateDate) VALUES (@ReminderId, @PropertyId, @CreateBy, @RenReportId, 2, 0, @CreateDate)"
                objDB.AddParameter("ReminderId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.ExecuteQuery()
            End If
        End If
        objDB.ClearParameter()
    End Sub

    Private Sub dbProperty(ByVal objDB As Database, ByVal strContactId As String)
        Dim myDT As New Data.DataTable
        myDT = CType(ViewState("DataTable"), Data.DataTable)
        If Not myDT Is Nothing Then
            For Each myrow As Data.DataRow In myDT.Rows
                If myrow.Item("Status") = "N" And myrow.Item("Visible") = "1" Then
                    'insert
                    objDB.dbVariable.SQLString = "INSERT INTO AW_RenProperty (RenPropertyId, RenContactId, CountryId, " & _
                                                "StateId, LocationId, RoadId, ProjectId, PropertyTypeId, ListType, " & _
                                                "PriceFrom, PriceTo, RenId) VALUES(@RenPropertyId, @RenContactId, @CountryId, " & _
                                                "@StateId, @LocationId, @RoadId, @ProjectId, @PropertyTypeId, @ListType, " & _
                                                "@PriceFrom, @PriceTo, @RenId)"
                    objDB.AddParameter("RenPropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("RenProId").ToString))
                    objDB.AddParameter("RenContactId", Data.SqlDbType.UniqueIdentifier, New Guid(strContactId))
                    objDB.AddParameter("RenId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
                    If myrow.Item("CountryId").ToString = "" Then
                        objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    Else
                        objDB.AddParameter("CountryId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("CountryId").ToString))
                    End If
                    If myrow.Item("StateId").ToString = "" Then
                        objDB.AddParameter("StateId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    Else
                        objDB.AddParameter("StateId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("StateId").ToString))
                    End If
                    If myrow.Item("LocationId").ToString = "" Then
                        objDB.AddParameter("LocationId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    Else
                        objDB.AddParameter("LocationId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("LocationId").ToString))
                    End If
                    If myrow.Item("RoadId").ToString = "" Then
                        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    Else
                        objDB.AddParameter("RoadId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("RoadId").ToString))
                    End If
                    If myrow.Item("ProjectId").ToString = "" Then
                        objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    Else
                        objDB.AddParameter("ProjectId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("ProjectId").ToString))
                    End If
                    If myrow.Item("PropertyTypeId").ToString = "" Then
                        objDB.AddParameter("PropertyTypeId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    Else
                        objDB.AddParameter("PropertyTypeId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("PropertyTypeId").ToString))
                    End If
                    If myrow.Item("ListTypeId").ToString = "" Then
                        objDB.AddParameter("ListType", Data.SqlDbType.Int, DBNull.Value)
                    Else
                        objDB.AddParameter("ListType", Data.SqlDbType.Int, CInt(myrow.Item("ListTypeId").ToString))
                    End If
                    If myrow.Item("PriceFrom").ToString = "0" Then
                        objDB.AddParameter("PriceFrom", Data.SqlDbType.Decimal, 0)
                    Else
                        objDB.AddParameter("PriceFrom", Data.SqlDbType.Decimal, CDbl(myrow.Item("PriceFrom").ToString))
                    End If
                    If myrow.Item("PriceTo").ToString = "0" Then
                        objDB.AddParameter("PriceTo", Data.SqlDbType.Decimal, 0)
                    Else
                        objDB.AddParameter("PriceTo", Data.SqlDbType.Decimal, CDbl(myrow.Item("PriceTo").ToString))
                    End If
                    objDB.ExecuteQuery()
                    objDB.ClearParameter()
                Else
                    If myrow.Item("Visible") = "0" Then
                        'delete
                        objDB.dbVariable.SQLString = "DELETE AW_RenProperty WHERE RenPropertyId=@RenPropertyId"
                        objDB.AddParameter("RenPropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(myrow.Item("RenPropertyId").ToString))
                        objDB.ExecuteQuery()
                        objDB.ClearParameter()
                    End If
                End If
            Next
        End If
    End Sub

    Private Function IsExistRecord(ByVal objDB As Database, ByVal dd As Integer, ByVal mm As Integer, ByVal yy As Integer) As Boolean
        Dim strContact As String
        Dim TempDT As New Data.DataTable
        If trUpdate.Visible Then
            strContact = "WHERE AW_RenReport.RenContactId=@RenContactId AND "
            objDB.AddParameter("RenContactId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlName.SelectedValue))
        Else
            strContact = " LEFT JOIN AW_RenContact ON AW_RenReport.RenContactId = AW_RenContact.RenContactId WHERE " & _
                        "AW_RenContact.Name=@Name AND "
            objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtName.Text.Trim)
        End If

        objDB.dbVariable.SQLString = "SELECT AW_RenReport.RenReportId FROM AW_RenReport " & strContact & "AW_RenReport.RenDate=@RenDate AND AW_RenReport.RenMonth=@RenMonth " & _
                                    "AND AW_RenReport.RenYear=@RenYear and AW_RenReport.RenReportType=1 "
        objDB.AddParameter("RenDate", Data.SqlDbType.TinyInt, dd)
        objDB.AddParameter("RenMonth", Data.SqlDbType.TinyInt, mm)
        objDB.AddParameter("RenYear", Data.SqlDbType.Int, yy)
        objDB.FillData(TempDT, "Country", Database.SQLCommandType.NormalString)

        If TempDT.Rows.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Function IsExistName(ByVal objdb As Database) As Boolean

        Dim TempDT As New Data.DataTable
        objdb.dbVariable.SQLString = "SELECT Name FROM AW_RenContact WHERE Name=@EName AND CreateBy=@ECreateBy " & _
                                    "AND StatusDelete=0"
        objdb.AddParameter("EName", Data.SqlDbType.NVarChar, txtName.Text.ToUpper.Trim)
        objdb.AddParameter("ECreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
        objdb.FillData(TempDT, "Name", Database.SQLCommandType.NormalString)
        If TempDT.Rows.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub AddNewRow()
        Dim MyDT As New Data.DataTable

        If ViewState("DataTable") Is Nothing Then
            DeclareColumn(MyDT)
            Dim MyRow As Data.DataRow
            MyRow = MyDT.NewRow()
            MyRow(0) = Guid.NewGuid
            If ddlCountry.SelectedValue = "" Then
                MyRow(1) = ""
            Else
                MyRow(1) = ddlCountry.SelectedItem.Text
            End If
            MyRow(2) = ddlCountry.SelectedValue
            If ddlState.SelectedValue = "" Then
                MyRow(3) = ""
            Else
                MyRow(3) = ddlState.SelectedItem.Text
            End If
            MyRow(4) = ddlState.SelectedValue
            If ddlLocation.SelectedValue = "" Then
                MyRow(5) = ""
            Else
                MyRow(5) = ddlLocation.SelectedItem.Text
            End If
            MyRow(6) = ddlLocation.SelectedValue
            If ddlRoad.SelectedValue = "" Then
                MyRow(7) = ""
            Else
                MyRow(7) = ddlRoad.SelectedItem.Text
            End If
            MyRow(8) = ddlRoad.SelectedValue
            If ddlProject.SelectedValue = "" Then
                MyRow(9) = ""
            Else
                MyRow(9) = ddlProject.SelectedItem.Text
            End If
            MyRow(10) = ddlProject.SelectedValue
            If ddlPropertyType.SelectedValue = "" Then
                MyRow(11) = ""
            Else
                MyRow(11) = ddlPropertyType.SelectedItem.Text
            End If
            MyRow(12) = ddlPropertyType.SelectedValue
            If ddlListType.SelectedValue = "" Then
                MyRow(13) = ""
            Else
                MyRow(13) = ddlListType.SelectedItem.Text
            End If
            MyRow(14) = ddlListType.SelectedValue
            If txtPriceFrom.Text = "" Then
                MyRow(15) = 0
            Else
                MyRow(15) = CDbl(txtPriceFrom.Text.Trim)
            End If
            If txtPriceTo.Text = "" Then
                MyRow(16) = 0
            Else
                MyRow(16) = CDbl(txtPriceTo.Text.Trim)
            End If
            MyRow(17) = "N"
            MyRow(18) = "1"
            MyDT.Rows.Add(MyRow)
        Else
            MyDT = CType(ViewState("DataTable"), Data.DataTable)
            Dim MyRow As Data.DataRow
            MyRow = MyDT.NewRow()
            MyRow(0) = Guid.NewGuid
            If ddlCountry.SelectedValue = "" Then
                MyRow(1) = ""
            Else
                MyRow(1) = ddlCountry.SelectedItem.Text
            End If
            MyRow(2) = ddlCountry.SelectedValue
            If ddlState.SelectedValue = "" Then
                MyRow(3) = ""
            Else
                MyRow(3) = ddlState.SelectedItem.Text
            End If
            MyRow(4) = ddlState.SelectedValue
            If ddlLocation.SelectedValue = "" Then
                MyRow(5) = ""
            Else
                MyRow(5) = ddlLocation.SelectedItem.Text
            End If
            MyRow(6) = ddlLocation.SelectedValue
            If ddlRoad.SelectedValue = "" Then
                MyRow(7) = ""
            Else
                MyRow(7) = ddlRoad.SelectedItem.Text
            End If
            MyRow(8) = ddlRoad.SelectedValue
            If ddlProject.SelectedValue = "" Then
                MyRow(9) = ""
            Else
                MyRow(9) = ddlProject.SelectedItem.Text
            End If
            MyRow(10) = ddlProject.SelectedValue
            If ddlPropertyType.SelectedValue = "" Then
                MyRow(11) = ""
            Else
                MyRow(11) = ddlPropertyType.SelectedItem.Text
            End If
            MyRow(12) = ddlPropertyType.SelectedValue
            If ddlListType.SelectedValue = "" Then
                MyRow(13) = ""
            Else
                MyRow(13) = ddlListType.SelectedItem.Text
            End If
            MyRow(14) = ddlListType.SelectedValue
            If txtPriceFrom.Text = "" Then
                MyRow(15) = 0
            Else
                MyRow(15) = CDbl(txtPriceFrom.Text.Trim)
            End If
            If txtPriceTo.Text = "" Then
                MyRow(16) = 0
            Else
                MyRow(16) = CDbl(txtPriceTo.Text.Trim)
            End If
            MyRow(17) = "N"
            MyRow(18) = "1"
            MyDT.Rows.Add(MyRow)
        End If
        ViewState("DataTable") = MyDT
        repProperty.DataSource = MyDT
        repProperty.DataBind()
        VisibilityRepProperty()
    End Sub

    Private Sub DeclareColumn(ByVal MyDT As Data.DataTable)
        Dim RenProId As Data.DataColumn = New Data.DataColumn("RenProId")
        RenProId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(RenProId)
        Dim Country As Data.DataColumn = New Data.DataColumn("Country")
        Country.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Country)
        Dim CountryId As Data.DataColumn = New Data.DataColumn("CountryId")
        CountryId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(CountryId)
        Dim State As Data.DataColumn = New Data.DataColumn("State")
        State.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(State)
        Dim StateId As Data.DataColumn = New Data.DataColumn("StateId")
        StateId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(StateId)
        Dim Location As Data.DataColumn = New Data.DataColumn("Location")
        Location.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Location)
        Dim LocationId As Data.DataColumn = New Data.DataColumn("LocationId")
        LocationId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LocationId)
        Dim Road As Data.DataColumn = New Data.DataColumn("Road")
        Road.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Road)
        Dim RoadId As Data.DataColumn = New Data.DataColumn("RoadId")
        RoadId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(RoadId)
        Dim Project As Data.DataColumn = New Data.DataColumn("Project")
        Project.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Project)
        Dim ProjectId As Data.DataColumn = New Data.DataColumn("ProjectId")
        ProjectId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(ProjectId)
        Dim PropertyType As Data.DataColumn = New Data.DataColumn("PropertyType")
        PropertyType.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PropertyType)
        Dim PropertyTypeId As Data.DataColumn = New Data.DataColumn("PropertyTypeId")
        PropertyTypeId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PropertyTypeId)
        Dim ListType As Data.DataColumn = New Data.DataColumn("ListType")
        ListType.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(ListType)
        Dim ListTypeId As Data.DataColumn = New Data.DataColumn("ListTypeId")
        ListTypeId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(ListTypeId)
        Dim PriceFrom As Data.DataColumn = New Data.DataColumn("PriceFrom")
        PriceFrom.DataType = System.Type.GetType("System.Decimal")
        MyDT.Columns.Add(PriceFrom)
        Dim PriceTo As Data.DataColumn = New Data.DataColumn("PriceTo")
        PriceTo.DataType = System.Type.GetType("System.Decimal")
        MyDT.Columns.Add(PriceTo)
        Dim Status As Data.DataColumn = New Data.DataColumn("Status")
        Status.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Status)
        Dim Visible As Data.DataColumn = New Data.DataColumn("Visible")
        Visible.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Visible)
    End Sub

    Private Sub VisibilityRepProperty()
        For Each repitem As RepeaterItem In repProperty.Items
            If CType(repitem.FindControl("lblhidRepVisible"), Label).Text = "0" Then
                repitem.Visible = False
            Else
                repitem.Visible = True
            End If
        Next
    End Sub

    Protected Sub repProperty_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repProperty.ItemCommand
        If e.CommandName.ToUpper = "SAVE" Then
            'Dim MyDT As New Data.DataTable

            'MyDT.Rows(e.CommandArgument)(0) = CType(repProperty.Items(e.CommandArgument).FindControl("lblhidRepRenProId"), Label).Text
            'MyDT.Rows(e.CommandArgument)(1) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepCountry"), DropDownList).SelectedItem.Text
            'MyDT.Rows(e.CommandArgument)(2) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepCountry"), DropDownList).SelectedValue
            'MyDT.Rows(e.CommandArgument)(3) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepState"), DropDownList).SelectedItem.Text
            'MyDT.Rows(e.CommandArgument)(4) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepState"), DropDownList).SelectedValue
            'MyDT.Rows(e.CommandArgument)(5) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepLocation"), DropDownList).SelectedItem.Text
            'MyDT.Rows(e.CommandArgument)(6) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepLocation"), DropDownList).SelectedValue
            'MyDT.Rows(e.CommandArgument)(7) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepRoad"), DropDownList).SelectedItem.Text
            'MyDT.Rows(e.CommandArgument)(8) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepRoad"), DropDownList).SelectedValue
            'MyDT.Rows(e.CommandArgument)(9) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepProject"), DropDownList).SelectedItem.Text
            'MyDT.Rows(e.CommandArgument)(10) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepProject"), DropDownList).SelectedValue
            'MyDT.Rows(e.CommandArgument)(11) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepPropertyType"), DropDownList).SelectedItem.Text
            'MyDT.Rows(e.CommandArgument)(12) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepPropertyType"), DropDownList).SelectedValue
            'MyDT.Rows(e.CommandArgument)(13) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepListType"), DropDownList).SelectedItem.Text
            'MyDT.Rows(e.CommandArgument)(14) = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepListType"), DropDownList).SelectedValue
            'MyDT.Rows(e.CommandArgument)(15) = CType(repProperty.Items(e.CommandArgument).FindControl("txtRepPriceFrom"), TextBox).Text
            'MyDT.Rows(e.CommandArgument)(16) = CType(repProperty.Items(e.CommandArgument).FindControl("txtRepPriceTo"), TextBox).Text
            'MyDT.Rows(e.CommandArgument)(17) = MyDT.Rows(e.CommandArgument)(17).ToString
            'MyDT.Rows(e.CommandArgument)(18) = MyDT.Rows(e.CommandArgument)(18).ToString
            ''Next
            'MyDT.AcceptChanges()
            ''End If
            'ViewState("DataTable") = MyDT
            'repProperty.DataSource = MyDT
            'repProperty.DataBind()
            'VisibilityRepProperty()
        ElseIf e.CommandName.ToUpper = "CANCEL" Then
            'Dim lbtRepCountry, lbtRepState, lbtRepLocation, lbtRepRoad, lbtRepProject, _
            'lbtRepPropertyType, lbtRepListType, lbtRepPriceFrom, lbtRepPriceTo As LinkButton
            'Dim ddlRepCountry, ddlRepState, ddlRepLocation, ddlRepRoad, ddlRepProject, _
            'ddlRepPropertyType, ddlRepListType As DropDownList
            'Dim txtRepPriceFrom, txtRepPriceTo As TextBox
            'Dim btnMinus, btnSave, btnCancel As Button
            'lbtRepCountry = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepCountry"), LinkButton)
            'lbtRepState = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepState"), LinkButton)
            'lbtRepLocation = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepLocation"), LinkButton)
            'lbtRepRoad = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepRoad"), LinkButton)
            'lbtRepProject = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepProject"), LinkButton)
            'lbtRepPropertyType = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepPropertyType"), LinkButton)
            'lbtRepListType = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepListType"), LinkButton)
            'lbtRepPriceFrom = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepPriceFrom"), LinkButton)
            'lbtRepPriceTo = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepPriceTo"), LinkButton)
            'ddlRepCountry = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepCountry"), DropDownList)
            'ddlRepState = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepState"), DropDownList)
            'ddlRepLocation = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepLocation"), DropDownList)
            'ddlRepRoad = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepRoad"), DropDownList)
            'ddlRepProject = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepProject"), DropDownList)
            'ddlRepPropertyType = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepPropertyType"), DropDownList)
            'ddlRepListType = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepListType"), DropDownList)
            'txtRepPriceFrom = CType(repProperty.Items(e.CommandArgument).FindControl("txtRepPriceFrom"), TextBox)
            'txtRepPriceTo = CType(repProperty.Items(e.CommandArgument).FindControl("txtRepPriceTo"), TextBox)
            'btnMinus = CType(repProperty.Items(e.CommandArgument).FindControl("btnMinus"), Button)
            'btnSave = CType(repProperty.Items(e.CommandArgument).FindControl("btnSave"), Button)
            'btnCancel = CType(repProperty.Items(e.CommandArgument).FindControl("btnCancel"), Button)

            'lbtRepCountry.Visible = True
            'lbtRepState.Visible = True
            'lbtRepLocation.Visible = True
            'lbtRepRoad.Visible = True
            'lbtRepProject.Visible = True
            'lbtRepPropertyType.Visible = True
            'lbtRepListType.Visible = True
            'lbtRepPriceFrom.Visible = True
            'lbtRepPriceTo.Visible = True
            'btnMinus.Visible = True

            'ddlRepCountry.Visible = False
            'ddlRepState.Visible = False
            'ddlRepLocation.Visible = False
            'ddlRepRoad.Visible = False
            'ddlRepProject.Visible = False
            'ddlRepPropertyType.Visible = False
            'ddlRepListType.Visible = False
            'txtRepPriceFrom.Visible = False
            'txtPriceTo.Visible = False

        ElseIf e.CommandName.ToUpper = "MINUS" Then
            Dim MyDT As New Data.DataTable

            MyDT = CType(ViewState("DataTable"), Data.DataTable)

            MyDT.Rows(e.CommandArgument)(0) = MyDT.Rows(e.CommandArgument)(0).ToString
            MyDT.Rows(e.CommandArgument)(1) = MyDT.Rows(e.CommandArgument)(1).ToString
            MyDT.Rows(e.CommandArgument)(2) = MyDT.Rows(e.CommandArgument)(2).ToString
            MyDT.Rows(e.CommandArgument)(3) = MyDT.Rows(e.CommandArgument)(3).ToString
            MyDT.Rows(e.CommandArgument)(4) = MyDT.Rows(e.CommandArgument)(4).ToString
            MyDT.Rows(e.CommandArgument)(5) = MyDT.Rows(e.CommandArgument)(5).ToString
            MyDT.Rows(e.CommandArgument)(6) = MyDT.Rows(e.CommandArgument)(6).ToString
            MyDT.Rows(e.CommandArgument)(7) = MyDT.Rows(e.CommandArgument)(7).ToString
            MyDT.Rows(e.CommandArgument)(8) = MyDT.Rows(e.CommandArgument)(8).ToString
            MyDT.Rows(e.CommandArgument)(9) = MyDT.Rows(e.CommandArgument)(9).ToString
            MyDT.Rows(e.CommandArgument)(10) = MyDT.Rows(e.CommandArgument)(10).ToString
            MyDT.Rows(e.CommandArgument)(11) = MyDT.Rows(e.CommandArgument)(11).ToString
            MyDT.Rows(e.CommandArgument)(12) = MyDT.Rows(e.CommandArgument)(12).ToString
            MyDT.Rows(e.CommandArgument)(13) = MyDT.Rows(e.CommandArgument)(13).ToString
            MyDT.Rows(e.CommandArgument)(14) = MyDT.Rows(e.CommandArgument)(14).ToString
            MyDT.Rows(e.CommandArgument)(15) = MyDT.Rows(e.CommandArgument)(15).ToString
            MyDT.Rows(e.CommandArgument)(16) = MyDT.Rows(e.CommandArgument)(16).ToString
            MyDT.Rows(e.CommandArgument)(17) = MyDT.Rows(e.CommandArgument)(17).ToString
            MyDT.Rows(e.CommandArgument)(18) = "0"
            'Next
            MyDT.AcceptChanges()
            'End If
            ViewState("DataTable") = MyDT
            repProperty.DataSource = MyDT
            repProperty.DataBind()
            VisibilityRepProperty()
        ElseIf e.CommandName.ToUpper = "EDIT" Then
            'Dim lbtRepCountry, lbtRepState, lbtRepLocation, lbtRepRoad, lbtRepProject, _
            'lbtRepPropertyType, lbtRepListType, lbtRepPriceFrom, lbtRepPriceTo As LinkButton
            'Dim lbtRepPriceFrom, lbtRepPriceTo As LinkButton
            'Dim ddlRepCountry, ddlRepState, ddlRepLocation, ddlRepRoad, ddlRepProject, _
            'ddlRepPropertyType, ddlRepListType As DropDownList
            'Dim txtRepPriceFrom, txtRepPriceTo As TextBox
            'Dim lblRepCountryValue, lblRepStateValue, lblRepLocationValue, lblRepRoadValue, _
            'lblRepProjectValue, lblRepPropertyTypeValue, lblRepListTypeValue As Label
            'Dim lblhidRepRenProId, lblhidRepStatus, lblhidRepVisible As Label
            'Dim btnMinus, btnSave, btnCancel As Button
            'lbtRepCountry = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepCountry"), LinkButton)
            'lbtRepState = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepState"), LinkButton)
            'lbtRepLocation = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepLocation"), LinkButton)
            'lbtRepRoad = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepRoad"), LinkButton)
            'lbtRepProject = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepProject"), LinkButton)
            'lbtRepPropertyType = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepPropertyType"), LinkButton)
            'lbtRepListType = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepListType"), LinkButton)
            'lbtRepPriceFrom = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepPriceFrom"), LinkButton)
            'lbtRepPriceTo = CType(repProperty.Items(e.CommandArgument).FindControl("lbtRepPriceTo"), LinkButton)
            'ddlRepCountry = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepCountry"), DropDownList)
            'ddlRepState = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepState"), DropDownList)
            'ddlRepLocation = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepLocation"), DropDownList)
            'ddlRepRoad = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepRoad"), DropDownList)
            'ddlRepProject = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepProject"), DropDownList)
            'ddlRepPropertyType = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepPropertyType"), DropDownList)
            'ddlRepListType = CType(repProperty.Items(e.CommandArgument).FindControl("ddlRepListType"), DropDownList)
            'txtRepPriceFrom = CType(repProperty.Items(e.CommandArgument).FindControl("txtRepPriceFrom"), TextBox)
            'txtRepPriceTo = CType(repProperty.Items(e.CommandArgument).FindControl("txtRepPriceTo"), TextBox)
            'lblRepCountryValue = CType(repProperty.Items(e.CommandArgument).FindControl("lblRepCountryValue"), Label)
            'lblRepStateValue = CType(repProperty.Items(e.CommandArgument).FindControl("lblRepStateValue"), Label)
            'lblRepLocationValue = CType(repProperty.Items(e.CommandArgument).FindControl("lblRepLocationValue"), Label)
            'lblRepRoadValue = CType(repProperty.Items(e.CommandArgument).FindControl("lblRepRoadValue"), Label)
            'lblRepProjectValue = CType(repProperty.Items(e.CommandArgument).FindControl("lblRepProjectValue"), Label)
            'lblRepPropertyTypeValue = CType(repProperty.Items(e.CommandArgument).FindControl("lblRepPropertyTypeValue"), Label)
            'lblRepListTypeValue = CType(repProperty.Items(e.CommandArgument).FindControl("lblRepListTypeValue"), Label)
            'lblhidRepRenProId = CType(repProperty.Items(e.CommandArgument).FindControl("lblhidRepRenProId"), Label)
            'lblhidRepStatus = CType(repProperty.Items(e.CommandArgument).FindControl("lblhidRepStatus"), Label)
            'lblhidRepVisible = CType(repProperty.Items(e.CommandArgument).FindControl("lblhidRepVisible"), Label)
            'btnMinus = CType(repProperty.Items(e.CommandArgument).FindControl("btnMinus"), Button)
            'btnSave = CType(repProperty.Items(e.CommandArgument).FindControl("btnSave"), Button)
            'btnCancel = CType(repProperty.Items(e.CommandArgument).FindControl("btnCancel"), Button)
            'GetddlCountry(ddlRepCountry)
            'ddlRepCountry.SelectedValue = lblRepCountryValue.Text
            'GetddlState(ddlRepState, ddlRepCountry)
            'ddlRepState.SelectedValue = lblRepStateValue.Text
            'GetddlLocation(ddlRepLocation, ddlRepState)
            'ddlRepLocation.SelectedValue = lblRepLocationValue.Text
            'GetddlRoad(ddlRepRoad, ddlRepLocation)
            'ddlRepRoad.SelectedValue = lblRepRoadValue.Text
            'GetddlProject(ddlRepProject, ddlRepRoad)
            'ddlRepProject.SelectedValue = lblRepProjectValue.Text
            'GetddlPropertyType(ddlRepPropertyType)
            'ddlRepPropertyType.SelectedValue = lblRepPropertyTypeValue.Text

            'ddlRepListType.SelectedValue = lblRepListTypeValue.Text
            'txtRepPriceFrom.Text = lbtRepPriceFrom.Text
            'txtRepPriceTo.Text = lbtRepPriceTo.Text
            'lblhidRepPopRenProId.Text = lblhidRepRenProId.Text
            'lblhidRepPopRowNum.Text = e.CommandArgument.ToString
            'lblhidRepPopStatus.Text = lblhidRepStatus.Text
            'lblhidRepPopVisible.Text = lblhidRepVisible.Text
            'mpeRenPropertyEntry.Show()
            'lbtRepCountry.Visible = False
            'lbtRepState.Visible = False
            'lbtRepLocation.Visible = False
            'lbtRepRoad.Visible = False
            'lbtRepProject.Visible = False
            'lbtRepPropertyType.Visible = False
            'lbtRepListType.Visible = False
            'lbtRepPriceFrom.Visible = False
            'lbtRepPriceTo.Visible = False
            'btnMinus.Visible = False

            ''visible = true then assign to ddl then assign value
            'ddlRepCountry.Visible = True
            'ddlRepState.Visible = True
            'ddlRepLocation.Visible = True
            'ddlRepRoad.Visible = True
            'ddlRepProject.Visible = True
            'ddlRepPropertyType.Visible = True
            'ddlRepListType.Visible = True
            'txtRepPriceFrom.Visible = True
            'txtPriceTo.Visible = True
            'GetddlCountry(ddlRepCountry)
            'ddlRepCountry.SelectedValue = lblRepCountryValue.Text
            'GetddlState(ddlRepState, ddlRepCountry)
            'ddlRepState.SelectedValue = lblRepStateValue.Text
            'GetddlLocation(ddlRepLocation, ddlRepState)
            'ddlRepLocation.SelectedValue = lblRepLocationValue.Text
            'GetddlRoad(ddlRepRoad, ddlRepLocation)
            'ddlRepRoad.SelectedValue = lblRepRoadValue.Text
            'GetddlProject(ddlRepProject, ddlRepRoad)
            'ddlRepProject.SelectedValue = lblRepProjectValue.Text
            'GetddlPropertyType(ddlRepPropertyType)
            'ddlPropertyType.SelectedValue = lblRepPropertyTypeValue.Text
            'ddlListType.SelectedValue = lblRepListTypeValue.Text
        End If
    End Sub

    Protected Sub btnAddMore_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddMore.Click
        AddNewRow()
        ddlCountry.SelectedIndex = 0
        ddlState.SelectedIndex = 0
        ddlLocation.SelectedIndex = 0
        ddlRoad.SelectedIndex = 0
        ddlProject.SelectedIndex = 0
        ddlPropertyType.SelectedIndex = 0
        ddlListType.SelectedIndex = 0
        txtPriceFrom.Text = ""
        txtPriceTo.Text = ""
    End Sub

    'Protected Sub btnRepSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRepSave.Click
    '    Dim MyDT As New Data.DataTable

    '    MyDT = ViewState("DataTable")

    '    MyDT.Rows(lblhidRepPopRowNum.Text)(0) = lblhidRepPopRenProId.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(1) = ddlRepCountry.SelectedItem.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(2) = ddlRepCountry.SelectedValue
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(3) = ddlRepState.SelectedItem.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(4) = ddlRepState.SelectedValue
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(5) = ddlRepLocation.SelectedItem.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(6) = ddlRepLocation.SelectedValue
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(7) = ddlRepRoad.SelectedItem.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(8) = ddlRepRoad.SelectedValue
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(9) = ddlRepProject.SelectedItem.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(10) = ddlRepProject.SelectedValue
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(11) = ddlRepPropertyType.SelectedItem.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(12) = ddlRepPropertyType.SelectedValue
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(13) = ddlRepListType.SelectedItem.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(14) = ddlRepListType.SelectedValue
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(15) = txtRepPriceFrom.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(16) = txtRepPriceTo.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(17) = lblhidRepPopStatus.Text
    '    MyDT.Rows(lblhidRepPopRowNum.Text)(18) = lblhidRepPopVisible.Text
    '    'Next
    '    MyDT.AcceptChanges()
    '    'End If
    '    ViewState("DataTable") = MyDT
    '    repProperty.DataSource = MyDT
    '    repProperty.DataBind()
    '    VisibilityRepProperty()
    'End Sub

    'Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    '    mpeRenPropertyEntry.Hide()
    'End Sub

    Protected Sub ddlName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlName.SelectedIndexChanged
        If ddlName.SelectedValue = "" Then
            txtName.Text = String.Empty
        Else
            txtName.Text = ddlName.SelectedItem.Text
            Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))

            objDB.OpenConnection()
            Dim TempDT As New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT Name, Phone, Mobile, Fax, Company, Email, Address, Status " & _
                                        "FROM AW_RenContact WHERE RenContactId=@ContactId"
            objDB.AddParameter("ContactId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlName.SelectedValue))
            objDB.FillData(TempDT, "Contact", Database.SQLCommandType.NormalString)

            For Each dtRow As Data.DataRow In TempDT.Rows
                txtPhone.Text = dtRow.Item("Phone").ToString
                txtMobile.Text = dtRow.Item("Mobile").ToString
                txtFax.Text = dtRow.Item("Fax").ToString
                txtCompany.Text = dtRow.Item("Company").ToString
                txtEmail.Text = dtRow.Item("Email").ToString
                txtAddress.Text = dtRow.Item("Address").ToString
                ddlStatus.SelectedValue = dtRow.Item("Status").ToString
            Next

            TempDT.Clear()
            TempDT.Reset()

            DeclareColumn(TempDT)
            objDB.dbVariable.SQLString = "SELECT RP.RenPropertyId, C.Country, RP.CountryId, S.State, RP.StateId, " & _
                                        "L.Location, RP.LocationId, R.Road, RP.RoadId, P.Project, RP.ProjectId, " & _
                                        "PP.Type AS PropertyType, RP.PropertyTypeId, " & _
                                        "CASE RP.ListType WHEN '0' THEN 'SR - Sales Residential' " & _
                                        "WHEN '1' THEN 'SC - Sales Commercial' WHEN '2' THEN 'SI - Sales Industrial' " & _
                                        "WHEN '3' THEN 'SL - Sales Land' WHEN '4' THEN 'RR - Rent Residential' " & _
                                        "WHEN '5' THEN 'RC - Rent Commercial' WHEN '6' THEN 'RI - Rent Industrial' " & _
                                        "WHEN '7' THEN 'RL - Rent Land' ELSE '' END as ListType, RP.ListType as ListTypeId, " & _
                                        "RP.PriceFrom, RP.PriceTo, 'O' AS Status, '1' AS Visible FROM AW_RenProperty RP " & _
                                        "LEFT JOIN AW_Country C ON RP.CountryId = C.CountryId LEFT JOIN AW_State S ON " & _
                                        "RP.StateId = S.StateId LEFT JOIN AW_Location L ON RP.LocationId = L.LocationId " & _
                                        "LEFT JOIN AW_Road R ON RP.RoadId = R.RoadId LEFT JOIN AW_Project P ON " & _
                                        "RP.ProjectId = P.ProjectId LEFT JOIN AW_PropertyType PP ON RP.PropertyTypeID = PP.TypeId " & _
                                        "WHERE RP.RenContactId=@RenContactId"
            objDB.AddParameter("RenContactId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlName.SelectedValue))
            objDB.FillData(TempDT, "AW_RenProperty", Database.SQLCommandType.NormalString)
            objDB.CloseConnection()
            repProperty.DataSource = TempDT
            repProperty.DataBind()
            ViewState("DataTable") = TempDT
            VisibilityRepProperty()
            objDB.CloseConnection()
        End If
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        trNew.Visible = False
        trUpdate.Visible = True
        txtName.Text = String.Empty
        txtPhone.Text = String.Empty
        txtMobile.Text = String.Empty
        txtFax.Text = String.Empty
        txtEmail.Text = String.Empty
        txtCompany.Text = String.Empty
        txtAddress.Text = String.Empty
    End Sub

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        Try
            objDB.InitDbTrans()
            objDB.dbVariable.SQLString = "UPDATE AW_RenReport SET UpdateBy=@UpdateBy, UpdateDate=@UpdateDate, StatusDelete=1 " & _
                                        "WHERE RenReportId=@RenReportId"
            objDB.AddParameter("UpdateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("RenReportId", Data.SqlDbType.UniqueIdentifier, New Guid(lblRenReportUID.Text.Trim))
            objDB.ExecuteQuery()
            If ddlInput.SelectedValue = "2" Then
                objDB.dbVariable.SQLString = "UPDATE AW_Reminder SET StatusDelete=1 " & _
                                        "WHERE AffectedId=@AffectedId"
                objDB.AddParameter("AffectedId", Data.SqlDbType.UniqueIdentifier, New Guid(lblRenReportUID.Text.Trim))
                objDB.ExecuteQuery()
            End If
            objDB.DbTransCommit()
            objDB.CloseConnection()
            Response.Redirect("RenReport.aspx")
        Catch ex As Exception
            lblMsgError.Text = ex.Message
            divError.Visible = True
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
        End Try


    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        If Session("Back") Is Nothing Then
            Response.Redirect("RenReport.aspx")
        Else
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            Response.Redirect(arr(0).ToString)
        End If
    End Sub
End Class
